package com.TropicalFlavor.service;

import com.TropicalFlavor.dao.UserDao;
import com.TropicalFlavor.po.MarketUser;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.Iterator;
import java.util.List;

@Transactional
@Service
public class AdminServiceImpl implements AdminService{

    @Resource
    private UserDao userDao;

    @Override
    public boolean InsertMarketUser(MarketUser marketUser) {
        if (!userDao.InsertUser(marketUser)) {
            return false;
        }
        return true;
    }

    @Override
    public boolean DeleteMarketUser(String UID) {
        if(!userDao.DeleteUser(userDao.SelectUser(UID))){
            return false;
        }
        return true;
    }

//    @Override
//    public List<MarketUser> ShowUser() {
//        return userDao.ShowUser();
//    }
    @Override
    public List<MarketUser> ShowUser() {
        List<MarketUser> marketUserList = userDao.ShowUser();
        Iterator<MarketUser> i = marketUserList.iterator();
        while (i.hasNext()){
            if(i.next().getUID().substring(0,4).equals("ADMI")){
                i.remove();
            }
        }
        return marketUserList;
    }

    //修改用户信息
    @Override
    public boolean ChangeUserInfo(MarketUser marketUser) {
        if(!userDao.ChangeInfo(marketUser))
            return false;
        return true;
    }
}
